<?php

declare(strict_types=1);

namespace app\admin\controller\gm;

use think\facade\Request;
use app\common\service\GmTgczlogsTqk as S;
use app\common\model\GmTgczlogsTqk as M;

class TgczlogsTqk extends  \app\admin\controller\Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    // 列表
    public function index()
    {
        if (Request::isAjax()) {
            return $this->getJson(M::getList());
        }
        return $this->fetch('index', ['ServerLs' => M::getServerLsSelect()]);
    }

    // 查询用户名
    public function queryuname()
    {

        $data = M::getqueryuname(Request::post('actorname'), Request::post('serverid'));
        $response = [
            'msg' => '操作成功',
            'code' => 200,
            'data' => $data,
        ];
        return json($response);
    }

    // 添加
    public function add()
    {
        if (Request::isAjax()) {
            return $this->getJson(S::goAdd(Request::post()));
            // $test = S::goAdd(Request::post());
            // return $test;
        }
        return $this->fetch('add', ['ServerLs' => M::getServerLsSelect()]);
    }


    // 修改玩家对应的推广人员
    public function updateu2r()
    {
        if (Request::isAjax()) {
            try {
                M::MoPalyerNweUser(Request::post('actorname'), Request::post('adminuser'));
                $response = ['msg' => '操作成功', 'code' => 200,];
                return json($response);
            } catch (\Throwable $th) {
                $response = ['msg' => '操作失败', 'code' => 201,];
                return json($response);
            }
        }
        return $this->fetch('update_u2r', ['userData' => M::getSelect()]);
    }

    // 区服冠名
    public function updateservername()
    {
        if (Request::isAjax()) {
            try {
                M::MoServerName(Request::post('serverid'), Request::post('servername'));
                $response = ['msg' => '操作成功', 'code' => 200,];
                return json($response);
            } catch (\Throwable $th) {
                $response = ['msg' => '操作失败', 'code' => 201,];
                return json($response);
            }
        }
        return $this->fetch('updateservername', ['ServerLs' => M::getServerLsSelect()]);
    }


    // 修改玩家密码
    public function updatePwd()
    {
        if (Request::isAjax()) {
            try {
                M::MoPalyerPwd(Request::post('actorname'), Request::post('newpassword'));
                $response = ['msg' => '操作成功', 'code' => 200,];
                return json($response);
            } catch (\Throwable $th) {
                $response = ['msg' => '操作失败'.$th, 'code' => 201,];
                return json($response);
            }
        }
        return $this->fetch('update_pwd', ['ServerLs' => M::getServerLsSelect()]);
    }


    // 删除
    public function remove($id)
    {
        return $this->getJson(S::goRemove($id));
    }

    // 批量删除
    public function batchRemove()
    {
        return $this->getJson(S::goBatchRemove(Request::post('ids')));
    }
}
